<template>
	<view class="indexs">
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo"><image :src="imgUrl + '/dzx_img33.png'" mode="widthFix"></image></view>
					<view class="index_wenben">{{ words.withdraw_apply.title.value }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;'">
			<view class="my_tixian_center">
				<view class="my_yue_item1">
					<image :src="imgUrl + '/dzx_img135.png'"></image>
					<view class="my_yue_item1_txt">
						<view class="my_yue_item1_t1">{{ words.withdraw_apply.words.capital.value }}</view>
						<view class="my_yue_item1_dis">
							<view class="my_yue_item1_t2">{{ detail['income'] }}</view>
							<view @tap="jump_txmingxi" class="my_yue_item1_t3">{{ words.withdraw_apply.words.txmx.value }}</view>
						</view>
					</view>
				</view>
				<view class="my_tixian_item2">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ words.withdraw_apply.words.money.value }}</text>
					</view>
					<view class="my_tixian_item2_dis">
						<input type="number" @input="inputMoney" :placeholder="words.withdraw_apply.words.money_placeholder.value" />
						<view class="my_tixian_item2_t1" @tap="all">{{ $t('page_my_tixian.Full_withdrawal') }}</view>
					</view>
					<view class="xuzhi">注：{{ words.withdraw_apply.words.min_money.value }}: {{ settlement.min_money }}</view>
				</view>
				<view class="my_tixian_item2">
					<view class="my_chongzhi_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Withdrawal_method') }}</text>
					</view>
					<view class="my_chongzhi_item3_list" v-for="(item, index) in settlement.pay_type" :key="index">
						<view class="my_chongzhi_item3_cont">
							<view class="my_chongzhi_item3_cont_l">
								<image v-if="item == 10" :src="imgUrl + '/dzx_img128.png'"></image>
								<image v-if="item == 20" :src="imgUrl + '/dzx_img129.png'"></image>
								<image v-if="item == 30" :src="imgUrl + '/dzx_img130.png'"></image>
								<image v-if="item == 40" :src="imgUrl + '/dzx_img130.png'"></image>
								<text v-if="item == 10">{{ $t('page_my_tixian.wx_lingqian') }}</text>
								<text v-if="item == 20">{{ $t('page_my_tixian.alipay') }}</text>
								<text v-if="item == 30">{{ $t('page_my_tixian.Bank_cardtransfer') }}</text>
								<text v-if="item == 40">{{ $t('page_my_tixian.f_xhuanzhang') }}</text>
							</view>
							<view class="my_chongzhi_item3_cont_r" v-if="is_choose == item"><image :src="imgUrl + '/dzx_img131.png'"></image></view>
							<view class="my_chongzhi_item3_cont_r" v-if="is_choose != item" :data-itme="item" @tap="changeChoose(item)">
								<image :src="imgUrl + '/dzx_img132.png'"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 20">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.User_name') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputZhiName" :placeholder="$t('page_my_tixian.placeholder1')" /></view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 20">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.alpay') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputZhifubao" :placeholder="$t('page_my_tixian.placeholder2')" /></view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 30">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Bank_account_name') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputHuming" :placeholder="$t('page_my_tixian.placeholder3')" /></view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 30">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Bank_account_number') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputZhanghao" :placeholder="$t('page_my_tixian.placeholder4')" /></view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 30">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Bank_name') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputMingchen" :placeholder="$t('page_my_tixian.placeholder5')" /></view>
				</view>
				<view class="my_tixian_item2" v-if="is_choose == 40">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.weixin') }}</text>
					</view>
					<view class="my_tixian_item2_dis"><input type="number" @input="inputWeixinhao" :placeholder="$t('page_my_tixian.placeholder6')" /></view>
				</view>

				<view class="my_tixian_item3">
					<view class="my_tixian_item3_btns" @tap="toSubmit">{{ words.withdraw_apply.words.submit.value }}</view>
				</view>
				<view class="my_tixian_item4">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Withdrawal_instructions') }}</text>
					</view>
					<view class="my_tixian_item4_list">
						<view class="my_tixian_item4_cont">{{ words.withdraw_apply.words.xieyi.value }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
// pages/shouye/shouye_zkc/shouye_zkc.js
const app = getApp();
let request = require('../../../utils/require');
export default {
	data() {
		return {
			navH: app.globalData.navHeight,
			gaodu: app.globalData.height,
			imgUrl: app.globalData.imgUrl,
			gaodutops: app.globalData.top,
			detail: [],
			words: [],
			settlement: [],
			money: 0,
			submsgSetting: [],
			is_choose: 10,
			zhifubao: '',
			zhiname: '',
			weixinhao: '',
			huming: '',
			zhanghao: '',
			mingchen: ''
		};
	},
	/**
	 * 生命周期函数--监听页面加载
	 */ onLoad() {
		var that = this;
		that.getSubmsgSetting();
	},
	onShow() {
		var that = this;
		that.getDealerData();
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {},
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {},
	methods: {
		changeChoose(e) {
			var that = this;
			console.log(e);
			that.is_choose= e
			console.log(that.is_choose);
		},
		jumpzuo() {
			uni.navigateBack();
		},
		jump_txmingxi() {
			console.log(7777);
			uni.navigateTo({
				url: '/pages/shopadmin/my_tixianmx/my_tixianmx'
			});
		},
		toSubmit() {
			var a = Number(this.detail['money']);
			if (this.money <= 0) {
				uni.showToast({
					icon: 'none',
					title: '请输入金额'
				});
				return;
			}
			if (this.money > a) {
				uni.showToast({
					icon: 'none',
					title: '你输入的金额大于可提现余额'
				});
				return;
			}
			if (this.is_choose == 20 && this.zhifubao == '') {
				uni.showToast({
					icon: 'none',
					title: '请输入支付宝账号'
				});
				return;
			}
			if (this.is_choose == 30 && this.huming == '') {
				uni.showToast({
					icon: 'none',
					title: '请输入银行卡户名'
				});
				return;
			}
			if (this.is_choose == 30 && this.zhanghao == '') {
				uni.showToast({
					icon: 'none',
					title: '请输入银行卡账号'
				});
				return;
			}
			if (this.is_choose == 30 && this.mingchen == '') {
				uni.showToast({
					icon: 'none',
					title: '请输入银行名称'
				});
				return;
			}
			if (this.is_choose == 40 && this.weixinhao == '') {
				uni.showToast({
					icon: 'none',
					title: '请输入你的微信号'
				});
				return;
			}

			var data = {
				token: uni.getStorageSync('token'),
				pay_type: this.is_choose,
				money: this.money,
				alipay_account: this.zhifubao,
				alipay_name: this.zhiname,
				bank_account: this.huming,
				bank_card: this.zhanghao,
				bank_name: this.mingchen,
				weixinhao: this.weixinhao
			};
			//api/user.dealer.withdraw/submit
			request.post(`index.php?s=/api/shop.withdraw/submit&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					//发起订阅消息
					this.onRequestSubscribeMessage();
					uni.showToast({
						title: res.data.msg
					});
					setTimeout(function() {
						uni.navigateBack({
							delta: 0
						});
					}, 2000);
				} else {
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					});
				}
			});
		},
		inputMoney(e) {
			var value = e.detail.value;
			this.money= value
		},
		inputZhiName(e) {
			var value = e.detail.value;
			this.zhiname= value
		},
		inputZhifubao(e) {
			var value = e.detail.value;
			this.zhifubao= value
		},
		inputWeixinhao(e) {
			var value = e.detail.value;
			this.weixinhao= value
		},
		inputHuming(e) {
			var value = e.detail.value;
			this.huming= value
		},
		inputZhanghao(e) {
			var value = e.detail.value;
			this.zhanghao= value
		},
		inputMingchen(e) {
			var value = e.detail.value;
			this.mingchen= value
		},
		/**
		 * 订阅消息 => [提现通知]
		 */
		onRequestSubscribeMessage() {
			var that = this,
				tmplIds = [],
				dealerSubmsg = that.submsgSetting.dealer;
			dealerSubmsg.withdraw_01.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_01.template_id);
			dealerSubmsg.withdraw_02.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_02.template_id);
			if (tmplIds.length > 0) {
				wx.requestSubscribeMessage({
					tmplIds,
					success(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/shopadmin/center'
							});
						}, 1000);
					},
					fail(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/shopadmin/center'
							});
						}, 1000);
					},
					complete(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/shopadmin/center'
							});
						}, 1000);
					}
				});
			}
		},
		all() {
			this.money= this.detail['income']
		},
		getSubmsgSetting() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/wxapp.submsg/setting&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				console.log(res.data.data.setting, 778877);
				that.submsgSetting= res.data.data.setting
			});
		},
		getDealerData() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/shop.worker/withdraw&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					console.log(res.data.data.words, 88877890);
					this.detail = res.data.data.detail;
					this.words = res.data.data.words;
					this.settlement = res.data.data.settlement;
					this.is_choose = res.data.data.settlement.pay_type[0];
				}
			});
		}
	}
};
</script>
<style>
@import './my_tixian.css';
</style>
